Skip to content

Add py.typed & type check package#3

Open
comkieffer wants to merge 4 commits intoattie:masterfrom
comkieffer:add-pytyped
Open

Add py.typed & type check package#3
comkieffer wants to merge 4 commits intoattie:masterfrom
comkieffer:add-pytyped

Conversation

@comkieffer
Copy link

@comkieffer comkieffer commented Dec 6, 2024

Update the package by

  • adding a py.typed file to signal to type checkers that the package contains type annotations;
  • relaxing the version range of pySerial to allow versions greater than 3.4

Doing this showed some issues with the current type annotation, so I went ahead and updated them. They mostly boil down to

  • replace collections.namedtuple with typing.NamedTuple
  • add None checks to the result of issue_command

The individual commits have more details.

Thibaud Chupin added 2 commits December 6, 2024 17:12
The `py.typed` file is marker that signals to type checkers that the
package has type annotations. This is required for tools like mypy to
make use of the type annotations.
Allow all pySerial releases in the 3.X series. This relaxes the previous
requirement (`==3.4`) but from looking at the changelog of `pySerial`
there do not seem to be any changes in the 3.X branch that could cause
any incompatibility.
Thibaud Chupin added 2 commits December 31, 2024 13:47
Type checkers like `mypy` do not actually run the code they are checking.
This makes certain legal constructs problematic for them.

In this case, constructing the `namedtuple` from the keys of a
dictionary makes it impossible for the type checker to know the names of
the values of the tuple.

Instead, we use a `typing.NamedTuple` and list the fields manually. With
this change, the type checker knows the names of the fields and their
expected type.
To replicate this check, run

pip install types-pyserial mypy
python -m mypy -p koradctl
@comkieffer comkieffer changed the title Update package Add py.typed & type check package Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant